<?php
/**
 * Created by PhpStorm.
 * User: Akuma
 * Date: 2017/9/17
 * Time: 8:04
 */

namespace App\BCAM\CMVariable;


use Illuminate\Support\Debug\Dumper;

class CMVariable
{
    public static $appKey;
    /**
     * 返回变量名
     * 注:在laravel中无效,因为这是全局变量,框架中使用的都是方法,局部变量
     * @param $val
     * @param null $scope
     * @return mixed
     */
    public static function getName(&$val,$scope = null){
        $scope = $scope == null ? $GLOBALS : $scope;//如果没有范围则在globals中寻找
        //有可能存在相同变量,先改变其值
        $temp = $val;
        $val = 'tmpValue'.mt_rand();
        $name = array_search($val,$scope,true);
        $val = $temp;
        return $name;
    }

    public static function compareRes(...$args){
        $newArgs = collect($args);
        if($newArgs->first() == self::$appKey){
            //TODO
        }
        foreach ($args as $x) {
            (new Dumper())->dump($x);
        }
    }

}